package net.realsee.controller.wcs.data;

import cn.dev33.satoken.annotation.SaCheckPermission;
import lombok.RequiredArgsConstructor;
import net.realsee.common.annotation.Log;
import net.realsee.common.annotation.RepeatSubmit;
import net.realsee.common.enums.BusinessType;
import net.realsee.common.utils.poi.ExcelUtil;
import net.realsee.domain.wcs.data.bo.WcsCharactAttrBo;
import net.realsee.domain.wcs.data.vo.WcsCharactAttrVo;
import net.realsee.framework.core.controller.BaseController;
import net.realsee.framework.core.domain.PageQuery;
import net.realsee.framework.core.domain.R;
import net.realsee.framework.core.page.TableDataInfo;
import net.realsee.framework.core.validate.AddGroup;
import net.realsee.framework.core.validate.EditGroup;
import net.realsee.service.wcs.data.IWcsCharactAttrService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * 特性属性值列
 *
 * @author realsee
 * @date 2023-08-11
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/wcs/charactAttr")
public class WcsCharactAttrController extends BaseController {

    private final IWcsCharactAttrService iWcsCharactAttrService;

    /**
     * 查询特性属性值列列表
     */
    @SaCheckPermission("wcs:charactAttr:list")
    @GetMapping("/list")
    public TableDataInfo<WcsCharactAttrVo> list(WcsCharactAttrBo bo, PageQuery pageQuery) {
        return iWcsCharactAttrService.selectVoPage(bo, pageQuery);
    }

    /**
     * 导出特性属性值列列表
     */
    @SaCheckPermission("wcs:charactAttr:export")
    @Log(title = "特性属性值列", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(WcsCharactAttrBo bo, HttpServletResponse response) {
        List<WcsCharactAttrVo> list = iWcsCharactAttrService.selectVoList(bo);
        ExcelUtil.exportExcel(list, "特性属性值列", WcsCharactAttrVo.class, response);
    }

    /**
     * 获取特性属性值列详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("wcs:charactAttr:query")
    @GetMapping("/{id}")
    public R<WcsCharactAttrVo> getInfo(@NotNull(message = "主键不能为空")
                                       @PathVariable Long id) {
        return R.ok(iWcsCharactAttrService.selectVoById(id));
    }

    /**
     * 新增特性属性值列
     */
    @SaCheckPermission("wcs:charactAttr:add")
    @Log(title = "特性属性值列", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody WcsCharactAttrBo bo) {
        return toAjax(iWcsCharactAttrService.insertByBo(bo));
    }

    /**
     * 修改特性属性值列
     */
    @SaCheckPermission("wcs:charactAttr:edit")
    @Log(title = "特性属性值列", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody WcsCharactAttrBo bo) {
        return toAjax(iWcsCharactAttrService.updateByBo(bo));
    }

    /**
     * 删除特性属性值列
     *
     * @param ids 主键串
     */
    @SaCheckPermission("wcs:charactAttr:remove")
    @Log(title = "特性属性值列", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空") @PathVariable Long[] ids) {
        return toAjax(iWcsCharactAttrService.deleteWithValidByIds(Arrays.asList(ids)));
    }
}
